# Run python setup.py to generate wheel file, rename wheel file and copy it to install path.

# Set the variable passed from configure_file in package.cmake/package_fc.cmake
set(GIT_HASH "@GIT_HASH@")
set(Python3_EXECUTABLE @Python3_EXECUTABLE@)
set(PYTHON_LIBPATH @PYTHON_LIBPATH@)
set(PYTHON_PACKAGE_LIBPATH @PYTHON_PACKAGE_LIBPATH@)
set(PYTHON_PACKAGE_PATH @PYTHON_PACKAGE_PATH@)
set(TARGET_WHEEL @TARGET_WHEEL@)
set(CMAKE_INSTALL_PATH @ARG_CMAKE_INSTALL_PATH@)
set(ENV{COMMIT_ID} "${GIT_HASH}")

# Copy all libs file and exclude sym file.
message("cmake install prefix: ${CMAKE_INSTALL_PREFIX}")
file(COPY ${PYTHON_LIBPATH}/
     DESTINATION ${PYTHON_PACKAGE_LIBPATH}/lib
     REGEX ".*sym$" EXCLUDE)
file(RENAME ${PYTHON_PACKAGE_LIBPATH}/setup.py ${PYTHON_PACKAGE_PATH}/setup.py)
# Run python setup.py bdist_whell to generate origin wheel file.
execute_process(COMMAND ${Python3_EXECUTABLE} setup.py bdist_wheel
        WORKING_DIRECTORY ${PYTHON_PACKAGE_PATH})
file(GLOB ORIGIN_WHEEL "python_api/dist/*.whl")
# Rename origin wheel file and move to install path.
file(COPY ${ORIGIN_WHEEL} DESTINATION ${CMAKE_INSTALL_PATH})
# Remove temporary package path
file(REMOVE_RECURSE ${PYTHON_PACKAGE_PATH})